package com.wxg.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wxg.common.core.dao.mysql.global.Dict;
import com.wxg.common.core.dao.mysql.global.DictExample;
import com.wxg.dao.mysql.mapper.DictMapper;
import com.wxg.service.DictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @author void
 * @date 2019/6/11 14:41
 * @desc
 */
@Service
public class DictServiceImpl implements DictService {

    @Autowired
    private DictMapper dictMapper;

    @Override
    public Dict query(String name) {
        DictExample example = new DictExample();
        example.createCriteria().andNameEqualTo(name);
        List<Dict> list = dictMapper.selectByExample(example);
        if(!CollectionUtils.isEmpty(list)){
            return list.iterator().next();
        }
        return null;
    }

    @Override
    public PageInfo<Dict> queryAll() {
        Page page = PageHelper.startPage(1, 20);
        DictExample example = new DictExample();
        dictMapper.selectByExample(example);
        return page.toPageInfo();
    }
}
